<?php
	include_once 'framework/com.cebuindex.url/controller.php';
	include_once 'framework/com.cebuindex.auth/accessList.php';
	class webUser extends controller{
		public static $auth = null;
		public static function isGuest(){
			if(empty($_SESSION)){
				return true;
			}else{
				return false;
			}
		}
		public static function authenticationRedirect(){
			if(webUser::isGuest()){
				if(webUser::$auth){
					$splitdata = explode("/", systemConfig::$baseAuthUrl); 
					if(count($splitdata)==2){
						systemGlobals::$moduleName="";
					}
					parent::redirect(systemConfig::$baseAuthUrl);
				}
			}else{
				if(systemGlobals::$currentRequest==systemConfig::$baseAuthUrl){
					parent::redirect(systemConfig::$baseUrl);
				}else{
					webUser::authorizationRedirect();
				}
			}
		}
		public function authorizationRedirect(){
			if(accessList::$acl){
				if(!empty(accessList::$aclBaseKey)){
					if(array_key_exists(accessList::$aclBaseKey, $_SESSION)){
						$view = systemGlobals::$file;
						$user = $_SESSION[accessList::$aclBaseKey];
						$checkUser = accessList::checkUser($user);
						if(!empty($checkUser)){
							$pagesList = accessList::$pageList[$user];
							if(!in_array($view, $pagesList)){
								// redirect to error403
								systemGlobals::$moduleName="";
								$con = new controller();
								$con->redirect("error/error403");
								exit();
							}
						}else{
							// redirect to error403
							systemGlobals::$moduleName="";
							$con = new controller();
							$con->redirect("error/error403");
						}
					}else{
						// redirect to error403
						systemGlobals::$moduleName="";
						$con = new controller();
						$con->redirect("error/error403");
					}
				}else{
					// redirect to error403
					systemGlobals::$moduleName="";
					$con = new controller();
					$con->redirect("error/error403");
				}
			}
		}
	}